<?php 
include_once('connect.php');
function insert_rating ($maphim,$diem)
{
	if(mysql_query("insert into rate(diem) value($diem)"))
	{
		$rating = mysql_query("select * from rate order by marate DESC limit 1");
		$r=mysql_fetch_array($rating);
		if(mysql_query("insert into thongtinphim value($maphim,{$r['marate']},0)"))
			return true;
		else return false;
	}
	else return false;
}
	if(isset($_POST['star']))
	{
		if(insert_rating($_POST['maphim'],$_POST['star']))
			echo "Cám ơn bạn đã đánh giá !";
		else echo $_POST['maphim'];
	}
	else header("location:index.php");
?>